package com.qzsoft.system.repository.sys.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.qzsoft.system.modules.permission.dept.dto.DeptInfoDTO;
import com.qzsoft.system.repository.sys.entity.SysDeptEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 部门管理(SysDept)表数据库访问层
 *
 * @author sdmq
 * @since 2019-08-06 09:39:12
 */
@Mapper
public interface SysDeptDao extends BaseMapper<SysDeptEntity> {
    @Select("SELECT sr.id AS roleId, sr.name AS roleName, t.* FROM sys_dept t left join sys_role  sr on t.id=sr.dept_id AND sr.has_default = 1 AND t.id  LIKE concat(#{rootId},'%') ORDER BY t.pid,t.sort")
    List<SysDeptEntity> selectListAndDefaultRole(String rootId);

    @Select("SELECT sr.id AS roleId, sr.name AS roleName, t.* FROM sys_dept t left join sys_role  sr on t.id=sr.dept_id AND sr.has_default = 1 WHERE t.id  LIKE concat(#{rootId},'%') ORDER BY t.pid,t.sort")
    List<SysDeptEntity> selectOutListAndDefaultRole(String rootId);

    /**
     * 获取用户所有的角色相关信息
     * @param userId 用户id
     * @return 处理结果
     */
    List<DeptInfoDTO> getInfoByUserId(@Param("userId") Long userId);

}